package com.ledi.guns.modular.ledipay.controller;

import io.swagger.annotations.Api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ledi.guns.common.annotion.Permission;
import com.ledi.guns.common.persistence.model.vo.FeedBackVo;
import com.ledi.guns.core.base.tips.SuccessTip;
import com.ledi.guns.core.base.tips.Tip;
import com.ledi.guns.modular.ledipay.controller.req.feedback.FeedBackAdd;
import com.ledi.guns.modular.ledipay.controller.req.feedback.FeedBackAdd.SaveFeed;
import com.ledi.guns.modular.ledipay.controller.req.feedback.FeedBackAdd.UpdateFeed;
import com.ledi.guns.modular.ledipay.controller.req.feedback.FeedBackForm;
import com.ledi.guns.modular.ledipay.service.FeedbackService;

/**
 * 文件名称： com.ledi.guns.modular.ledipay.controller.req.FeedbackController.java<br/>
 * 初始作者： 钟小平<br/>
 * 创建日期： 2018年7月4日<br/>
 * 功能说明： 反馈Controller<br/>
 * =================================================<br/>
 * 修改记录：<br/>
 * 修改作者 日期 修改内容<br/>
 * ================================================<br/>
 * Copyright (乐迪教育科技有限公司-幼儿事业部) 2017-2018.All rights reserved.<br/>
 */
@Api
@RestController
@RequestMapping("/feedBack")
public class FeedbackController {

	@Autowired
	private FeedbackService feedbackService;

	/**
	 * @api {POST} /feedBack/list 反馈列表
	 * @apiVersion 1.3.0
	 * @apiGroup feedBack
	 * @apiName list
	 * @apiParam {int} type 反馈类型（0，功能优化1，使用问题，2其他）
	 * @apiParam {int} status 0未处理，1已处理
	 * @apiParam {Date} startTime 起始日期
	 * @apiParam {String} endTime 结束日期
	 * @apiSuccess {int} id 反馈id
	 * @apiSuccess {String} typeZh 反馈类型中文
	 * @apiSuccess {String} content 反馈内容
	 * @apiSuccess {String} imageUrl 图片列表
	 * @apiSuccess {Date} createTime 创建时间
	 * @apiSuccess {int} creatorId 创建人
	 * @apiSuccess {String} contact 联系方式
	 * @apiSuccess {String} creatorName 反馈人
	 * @apiSuccess {String} addMan 添加人
	 * @apiSuccess {String} updaterId 处理人
	 * @apiSuccess {String} updaterName 处理人名称
	 * @apiSuccess {Date} updateTime 处理时间
	 * @apiSuccess {int} status 0未完成1已完成
	 * @apiSuccess {String} statusZh 0未完成1已完成
	 * @apiSuccess {String} idea 处理意见
	 * @apiSuccess {int} code 返回编码（200成功）
	 * @apiSuccess {String} message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "asc": true,
	 *                    "condition": "",
	 *                    "current": 1,
	 *                    "limit": 2147483647,
	 *                    "offset": 0,
	 *                    "offsetCurrent": 0,
	 *                    "openSort": true,
	 *                    "orderByField": "",
	 *                    "pages": 1,
	 *                    "records": [
	 *                    {
	 *                    "contact": "17625320526",
	 *                    "content": "反馈内容",
	 *                    "createTime": "2018-07-04 16:40:51",
	 *                    "creatorId": 1,
	 *                    "creatorName": "乐迪yuyu",
	 *                    "id": 1,
	 *                    "idea": "",
	 *                    "imageUrl": [
	 *                    "image/2017/9/8/756d2e1c-afb1-43ff-aaf6-a2b628e1db54.jpg",
	 *                    "image/2018/1/5/f19b832b-bf42-4942-8707-3e716b6f4c6d.png"
	 *                    ],
	 *                    "source": 0,
	 *                    "status": 0,
	 *                    "statusZh": "未处理",
	 *                    "type": 0,
	 *                    "typeZh": "功能优化",
	 *                    "updateTime": "2018-07-04 16:41:39",
	 *                    "updaterId": "",
	 *                    "updaterName": ""
	 *                    }
	 *                    ],
	 *                    "searchCount": true,
	 *                    "size": 10,
	 *                    "total": 1
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	@RequestMapping(value = "/list")
	@Permission
	public Object list(@RequestBody FeedBackForm feedBackForm) {

		feedBackForm.checkOrder(FeedBackVo.class);
		Page<FeedBackVo> page = feedbackService.pageList(new Page<FeedBackVo>(feedBackForm.getPageNo(), feedBackForm.getPageSize()), feedBackForm);
		return SuccessTip.buildSuccess(page);
	}

	/**
	 * @api {POST} /feedBack/add 增加反馈
	 * @apiGroup feedBack
	 * @apiName add
	 * @apiParam {int} type 反馈类型（0，功能优化1，使用问题，2其他）
	 * @apiParam {String} content 反馈内容
	 * @apiParam {String} contact 联系方式
	 * @apiParam {Array} imageUrl 图片列表
	 * @apiParam {String} creatorName 反馈人
	 * @apiParam {int} status 0未处理1已处理(不传默认未处理)
	 * @apiParam {int} roleId 角色id
	 * @apiParam {String} idea 处理意见
	 * @apiVersion 1.2.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "type":0,
	 *                  "content":"反馈内容",
	 *                  "contact":"13835325126",
	 *                  "imageUrl":["a.jpg","b.jpg"],
	 *                  "creatorName":"刘大壮",
	 *                  "roleId":1,
	 *                  "idea":"ddd"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	@Permission
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public Tip addFeedBack(@RequestBody @Validated({ SaveFeed.class }) FeedBackAdd feedBackAdd) {

		feedbackService.addorUpdateFeedback(feedBackAdd);

		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {PUT} /feedBack/update 处理反馈
	 * @apiGroup feedBack
	 * @apiName update
	 * @apiParam {int} id 反馈id
	 * @apiParam {int} versionNo 版本号
	 * @apiParam {String} idea 处理意见
	 * @apiVersion 1.3.0
	 * @apiParamExample {json} Request-Example:
	 *                  {
	 *                  "id": 1,
	 *                  "versionNo": 1,
	 *                  "idea": "string"
	 *                  }
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "message": "成功"
	 *                    }
	 */
	@Permission
	@RequestMapping(value = "/update", method = RequestMethod.PUT)
	public Tip updateFeedBack(@RequestBody @Validated({ UpdateFeed.class }) FeedBackAdd feedBackAdd) {

		feedbackService.addorUpdateFeedback(feedBackAdd);

		return SuccessTip.buildSuccess();
	}

	/**
	 * @api {GET} /feedBack/getFeedBack/{id} 查看反馈
	 * @apiVersion 1.3.0
	 * @apiGroup feedBack
	 * @apiName getFeedBack
	 * @apiParam {int} id Id
	 * @apiSuccess {int} id 反馈id
	 * @apiSuccess {String} typeZh 反馈类型中文
	 * @apiSuccess {String} content 反馈内容
	 * @apiSuccess {String} imageUrl 图片列表
	 * @apiSuccess {Date} createTime 创建时间
	 * @apiSuccess {int} creatorId 创建人
	 * @apiSuccess {String} contact 联系方式
	 * @apiSuccess {String} creatorName 反馈人
	 * @apiSuccess {String} updaterId 处理人
	 * @apiSuccess {String} updaterName 处理人名称
	 * @apiSuccess {Date} updateTime 处理时间
	 * @apiSuccess {int} status 0未完成1已完成
	 * @apiSuccess {String} statusZh 0未完成1已完成
	 * @apiSuccess {String} idea 处理意见
	 * @apiSuccess {int} code 返回编码（200成功）
	 * @apiSuccess {String} message 返回说明
	 * @apiSuccessExample {json} Success-Response:
	 *                    {
	 *                    "code": 200,
	 *                    "data": {
	 *                    "asc": true,
	 *                    "condition": "",
	 *                    "current": 1,
	 *                    "limit": 2147483647,
	 *                    "offset": 0,
	 *                    "offsetCurrent": 0,
	 *                    "openSort": true,
	 *                    "orderByField": "",
	 *                    "pages": 1,
	 *                    "records": [
	 *                    {
	 *                    "contact": "17625320526",
	 *                    "content": "反馈内容",
	 *                    "createTime": "2018-07-04 16:40:51",
	 *                    "creatorId": 1,
	 *                    "creatorName": "乐迪yuyu",
	 *                    "id": 1,
	 *                    "idea": "",
	 *                    "imageUrl": [
	 *                    "image/2017/9/8/756d2e1c-afb1-43ff-aaf6-a2b628e1db54.jpg",
	 *                    "image/2018/1/5/f19b832b-bf42-4942-8707-3e716b6f4c6d.png"
	 *                    ],
	 *                    "source": 0,
	 *                    "status": 0,
	 *                    "statusZh": "未处理",
	 *                    "type": 0,
	 *                    "typeZh": "功能优化",
	 *                    "updateTime": "2018-07-04 16:41:39",
	 *                    "updaterId": "",
	 *                    "updaterName": ""
	 *                    }
	 *                    ],
	 *                    "searchCount": true,
	 *                    "size": 10,
	 *                    "total": 1
	 *                    },
	 *                    "message": "成功"
	 *                    }
	 */
	@RequestMapping(value = "/getFeedBack/{id}")
	@Permission
	public Object getFeedBack(@PathVariable("id") Integer id) {

		FeedBackVo back = feedbackService.findFeedBack(id);
		return SuccessTip.buildSuccess(back);
	}

}
